home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12909 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news.mixcom.com!usenet
  2. From: elja.inc@mixcom.com (Mike McWhinney)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Please help: need to read lines in text file
  5. Date: Wed, 03 Apr 1996 14:36:38 GMT
  6. Organization: MIX Communications
  7. Message-ID: <31628cbe.1910456@news.mixcom.com>
  8. References: <315fe5d1.1121568@news.mixcom.com> <4joubrINNrdl@keats.ugrad.cs.ubc.ca>
  9. NNTP-Posting-Host: llggll.mixcom.com
  10. X-Newsreader: Forte Agent .99d/16.182
  11.  
  12. c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) wrote:
  13.  
  14.  
  15. >char *readline(char *filename, int n)
  16.  
  17. [function contents deleted]
  18.  
  19.  
  20.  
  21. Kazimir, would you need an fclose(stream) in the function readline()
  22. before the return statement?
  23.  
  24. >                              if (nextchar == EOF || nextchar == '\n') {
  25. >            buffer[charcount++] = '\0';
  26. >            break;
  27. >        } else 
  28. >            buffer[charcount++] = nextchar;
  29. >    }
  30.                 fclose(stream); <-----------------Is this necessary?
  31. >    return realloc(buffer, charcount);
  32. >
  33.  
  34. I found that this function causes my program to work the first
  35. couple iterations, and then it produces unpredictable results.
  36. Also in main() don't you need to dynamical allocate storage
  37. space for 'str'?   My program won't work unless I do something
  38. like:
  39.  
  40. str = malloc(50);
  41.  
  42. Please help!!!
  43.  
  44. Thanks
  45.  
  46. Mike
  47.  
  48.